package com.itheima02.day11;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author 刘全
 * @date 2021/7/28
 */
public class Test4 {
    public static void main(String[] args) {
        //method1();
        //method2();
        //method3();
        //method4();

    }

    private static void method4() {
        //多个同数据类型的参数
        Stream<Integer> stream = Stream.of(1, 5, 9, 2, 4, 7, 3);
        stream.forEach(s -> System.out.println(s));
    }

    private static void method3() {
        //数组(通过Arrays方法调用)
        int[] arr = {5, 2, 1, 9, 7};
        IntStream stream = Arrays.stream(arr);
        stream.forEach(s -> System.out.println(s));
    }

    private static void method2() {
        //双列集合(间接调用,比如获取到所有键的集合再调用或获取到所有的键值对再调用)
        Map<String, Integer> map = new HashMap<>();
        map.put("pier", 23);
        map.put("wuer", 22);
        map.put("taoer", 24);
        Stream<Map.Entry<String, Integer>> stream = map.entrySet().stream();
        stream.forEach(s -> System.out.println(s));
    }

    private static void method1() {
        //单列集合(可以直接调用)
        ArrayList<String> list = new ArrayList<>();
        list.add("pier");
        list.add("wuer");
        list.add("taoer");
        Stream<String> stream = list.stream();
        stream.forEach(s -> System.out.println(s));
    }
}
